/*
 *  Copyright 2004 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.persistence.core;

import com.blandware.atleap.common.util.PartialCollection;
import com.blandware.atleap.common.util.QueryInfo;
import com.blandware.atleap.model.core.ContentField;
import com.blandware.atleap.model.core.ContentFieldValue;
import com.blandware.atleap.model.core.ContentLocale;

/**
 * <p>DAO for content field value</p>
 * <p><a href="ContentFieldValueDAO.java.html"><i>View Source</i></a></p>
 *
 * @author Sergey Zubtsovskiy <a href="mailto:sergey.zubtsovskiy@blandware.com">&lt;sergey.zubtsovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.13 $ $Date: 2006/08/03 10:07:36 $
 */
public interface ContentFieldValueDAO extends DAO {

	// ~ CRUD Methods ================================================================

	/**
	 * Creates new content field value
	 *
	 * @param contentFieldValue Content field value object that represents what
     * field value must be created
     * @param field Content field to which this content field value belongs
     * @param contentLocale Content locale that corresponds to this content
     * field value
	 * @return ID of created content field value
	 */
	public Long createContentFieldValue(ContentFieldValue contentFieldValue, ContentField field, ContentLocale contentLocale);

	/**
	 * Retrieves content field value with specified ID
	 *
	 * @param contentFieldValueId ID to search by
	 * @return Content field value or null if no content field value with specified ID exists in database
	 */
	public ContentFieldValue retrieveContentFieldValue(Long contentFieldValueId);

	/**
	 * Updates content field value
	 *
	 * @param contentFieldValue content field value to update
     * @param field field to which this CFV belongs
     * @param contentLocale content locale that corresponds to this CFV
	 */
	public void updateContentFieldValue(ContentFieldValue contentFieldValue, ContentField field, ContentLocale contentLocale);

	/**
	 * Deletes content field value
	 *
	 * @param contentFieldValue CFV of field to delete
	 */
	public void deleteContentFieldValue(ContentFieldValue contentFieldValue);

	// ~ Additional methods ================================================================

	/**
	 * Retrieves filtered/sorted collection of content field values
	 *
	 * @param queryInfo Object that contains information about how to filter and sort data
	 * @return Collection of content field values
	 */
	public PartialCollection listContentFieldValues(QueryInfo queryInfo);

	/**
	 * Searches for duplicates. Returns true if there is one or more field values with another ID, but which
	 * have the same field and locale
	 *
	 * @param contentFieldValue Field value to find duplicates for
	 * @param fieldId           ID of field
	 * @param localeIdentifier  Identifier of locale
	 * @return whether this content field value has duplicates
	 */
	public boolean hasDuplicates(ContentFieldValue contentFieldValue, Long fieldId, String localeIdentifier);

	// ~ Finders ================================================================


	/**
	 * Finds content field value by its field and locale
	 *
	 * @param field         Content field to search by
	 * @param contentLocale Locale to search by
	 * @return ContentFieldValue or null if nothing was found
	 */
	public ContentFieldValue findContentFieldValueByContentFieldAndLocale(ContentField field, ContentLocale contentLocale);

	/**
	 * Finds content field value by page URI, content field identifier and locale.
     * If nothing was found for specified locale, attempt to find the same for
     * default locale.
	 *
	 * @param uri              URI of page that contains content field
	 * @param identifier       Identifier of content field
	 * @param localeIdentifier Content locale identifier
	 * @return Content field value or null if nothing was found
	 */
	public ContentFieldValue findContentFieldValueByUriAndIdentifierAndLocale(String uri, String identifier, String localeIdentifier);

	/**
	 * Finds content field value by layout definition, field identifier and locale.
     * If nothing was found for specified locale, attempt to find the same for
     * default locale.
	 *
	 * @param definition       Struts tile definition layout that contains content field
	 * @param identifier       Identifier of content field
	 * @param localeIdentifier Content locale identifier
	 * @return Content field value or null if nothing was found
	 */
	public ContentFieldValue findContentFieldValueByDefinitionAndIdentifierAndLocale(String definition, String identifier, String localeIdentifier);

    /**
     * Finds content field value by localizable id, field identifier and locale.
     * If nothing was found for specified locale, attempt to find the same for
     * default locale.
     *
     * @param localizableId    Id of localizable object
     * @param identifier       Identifier of content field
     * @param localeIdentifier Content locale identifier
     * @return Content field value or null if nothing was found
     */
    public ContentFieldValue findContentFieldValueByLocalizableIdAndIdentifierAndLocale(Long localizableId, String identifier, String localeIdentifier);

}

